#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define STDIN
//#define DEBUG

#define MAX_LEN 105

int n;
int m[MAX_LEN];

typedef struct tagRem {
    int r;
    //通过此变量来判断是否已经保存过余数为r的数
    int l;//余数为r的最小数的长度，
    char v[MAX_LEN];
}Rem;

Rem rem_array[202];

int compute(int dn, int k) {
    int i, r = 1;
    for (i = 1; i < dn; i++) {
        r *= 10;
        r %= k;
    }
    return r;
}

void process() {
    int i;
    for (i = 0; i < n; ++i) {
        rem_array[i].r = i;
        rem_array[i].l = 0;
        memset(rem_array[i].v, '0', MAX_LEN * sizeof(char));
        rem_array[i].v[MAX_LEN-1] = '\0';
    }
    rem_array[0].r = 0;
    rem_array[0].l = 1;
    rem_array[0].v[0] = '0';
    rem_array[1].r = 1;
    rem_array[1].l = 1;
    rem_array[1].v[0] = '1';
#ifdef DEBUG
    for (i = 0; i < n; ++i) {
        printf("r: %d l: %d v: %s\n", rem_array[i].r, rem_array[i].l, rem_array[i].v);
    }
#endif



    int digit_cnt = 0;
    int rem = 0;
    int flag = 0;
    for (digit_cnt = 2; digit_cnt <= 100 && !flag; digit_cnt++) {
        rem = compute(digit_cnt, n);

#ifdef DEBUG
        printf("digit_cnt: %d rem: %d\n", digit_cnt, rem);
#endif
#ifdef DEBUG
        int j;
        for (j = 0; j < n; ++j) {
            printf("r: %d l: %d v: %s\n", 
                    rem_array[j].r, 
                    rem_array[j].l,
                    rem_array[j].v);
        }
        printf("\n");
#endif
        for (i = 0; i < n && !flag; i++) {
            if (rem_array[i].l == 0 || rem_array[i].l >= digit_cnt)
                continue;
            else {
                int new_r = (rem + rem_array[i].r) % n;
#ifdef DEBUG
                printf("new_rem: %d digit_cnt: %d rem: %d i: %d\n", new_r, digit_cnt, rem, i);
#endif
                if (rem_array[new_r].l == 0 || new_r == 0) {//得到新的余数
                    rem_array[new_r].r = new_r;
                    strncpy(rem_array[new_r].v, rem_array[i].v, 105);
                    rem_array[new_r].v[digit_cnt-1] = '1';
                    rem_array[new_r].l = digit_cnt;
                }
                if (new_r == 0) {
#ifdef DEBUG
                    printf("找到\n");
#endif
                    flag = 1;
                }
            }
        }
    }
    i = MAX_LEN-2;
    while(rem_array[0].v[i] == '0')
        i--;
    while(i >= 0) {
        printf("%c", rem_array[0].v[i]);
        i--;
    }
    printf("\n");


}

int main() {
#ifdef STDIN
    freopen("bin/1426.in", "r", stdin);
#endif

    while(1) {
        scanf("%d", &n);
        if (n == 0)
            break;

        process();
    }

    return 0;
}
